<template>
  <div class="search-result">
    <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
    >
      <van-cell class="article-item"  v-for="(item,index) in list" :key="index">
        <div slot="title" class="title text-l van-multi-ellipsis--l3">{{item.title}}</div>
        <div slot="label">
          <div class="cover-warp" v-if="item.cover.type===3">
            <div class="cover-warp-item"
                 v-for="(img,index) in item.cover.images"
                 :key="index"
            >
              <van-image fit="cover"
                         class="cover-item"
                         :src="img"
              />
            </div>
          </div>
          <div class="label-wrap">
            <span>{{item.aut_name}}</span>
            <span>{{item.comm_count}}</span>
            <span>{{item.pubdate|relativeTime}}</span>
          </div>
        </div>
        <van-image v-if="item.cover.type===1"
                   width="116"
                   height="73"
                   fit="cover"
                   class="right-cover"
                   :src="item.cover.images[0]"
        />
      </van-cell>
<!--      <van-cell v-for="(item,index) in list" :key="index" :title="item.title" />-->
    </van-list>
  </div>


</template>

<script>
import {getSearchResult} from '@/api/search'
export default {
  name: "SearchResult",
  props:{
    searchText:{
      type:String,
      required:true
    }
  },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page:1,
      perPage:10,

    };
  },
  methods: {
    async onLoad() {
      const {data}=await getSearchResult({
        page:this.page,
        per_page:this.perPage,
        q:this.searchText
      })
      const {results}=data.data
      this.list.push(...results)
      this.loading=false
      if (results.length){
        this.page++
      }else {
        this.finished=true
      }
    }
  }
}
</script>

<style scoped lang="less">
.search-result{
  position: fixed;
  left: 0;
  right: 0;
  top: 54px;
  bottom: 0;
  overflow-y:auto;
}
.article-item{
  .title{
    font-size: 10px;
    color: #3a3a3a;
    text-align: left;
  }
  /deep/.van-cell__value{
    flex: unset;
    width: 116px;
    height: 73px;
    margin-left: 12px;
  }
  .van-cell__label{
    text-align: left;
  }
  right-cover{
    width: 116px;
    height: 73px;
  }
  .cover-warp{
    padding: 15px 0;
    display: flex;
    .cover-warp-item{
      flex: 1;
      height: 73px;
      &:not(:last-child){
        padding-right:4px ;
      }
      .cover-item{
        width: 100%;
        height: 73px;
      }
    }
  }
  .label-wrap{
    font-size: 11px;
    color: #b4b4b4;
  }
  .label-wrap span{
    margin-right: 12px;
  }
}
</style>